# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>

pkgbase=serd
pkgname=(serd serd-docs)
pkgver=0.30.16
pkgrel=1
pkgdesc="Lightweight C library for RDF syntax supporting reading/ writing Turtle and NTriples"
arch=(loong64 x86_64)
url="https://drobilla.net/software/serd.html"
license=(custom:ISC)
makedepends=(doxygen meson python-sphinx)
options=(debug)
source=(https://download.drobilla.net/$pkgname-$pkgver.tar.xz{,.sig})
sha512sums=('1bc2e310027d52ea675aa261b52e89c4c1ccb622fa9fef11c874876de7821fe94672918ff58b9edcc7995daa70fc88b7ceb88fae61dd40f601285de1995b39ff'
            'SKIP')
b2sums=('0021125505bf23565a1cca24dc83eff3496fc11fe6b38dc07b68d800c7bd6a854923bc7c529161b659bd80cb7aa8c3b45e767f0841b57d4803d820e0016e2ed2'
        'SKIP')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package_serd() {
  depends=(glibc)
  optdepends=('serd-docs: for developer documentation')
  provides=(libserd-0.so)

  meson install -C build --destdir "$pkgdir"
  (
    cd "$pkgdir"
    _pick $pkgname-docs usr/share/doc
  )

  install -vDm 644 $pkgname-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_serd-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
  mv -v "$pkgdir/usr/share/doc/"serd{-0,}
}
